package com.nxk.modules.content.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.nxk.modules.content.dao.ConSwiperDao;
import com.nxk.modules.content.entity.ConSwiper;
import com.nxk.modules.content.service.ConSwiperService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class ConSwiperServiceImpl extends ServiceImpl<ConSwiperDao, ConSwiper> implements ConSwiperService {

    @Override
    @Transactional(readOnly = false)
    public boolean save(ConSwiper conSwiper) {
        if (StringUtils.isNotBlank(conSwiper.getId())) {
            return super.updateById(conSwiper);
        } else {
            return super.save(conSwiper);
        }
    }

    @Override
    public IPage<ConSwiper> page(ConSwiper conSwiper) {
        Page<ConSwiper> page = new Page<ConSwiper>(conSwiper.getPageNo(), conSwiper.getPageSize());
        QueryWrapper<ConSwiper> queryWrapper = new QueryWrapper<ConSwiper>();
        if (StringUtils.isNotBlank(conSwiper.getSwiperName())) {
            queryWrapper.lambda().like(ConSwiper::getSwiperName, conSwiper.getSwiperName());
        }
        queryWrapper.orderByAsc("sort").in("status", 1, 2);
        IPage<ConSwiper> result = super.page(page, queryWrapper);
        return result;

    }

    @Override
    @Transactional(readOnly = false)
    public boolean deleteById(String id) {
        return super.removeById(id);
    }


}